package com.android.baselibrary.base

import android.annotation.SuppressLint
import android.util.Log
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.android.baselibrary.customview.BaseCustomView
import com.android.baselibrary.customview.BaseCustomViewModel
import com.android.baselibrary.customview.BaseViewHolder

class BaseRecyclerAdapter<S : BaseCustomViewModel> : RecyclerView.Adapter<BaseViewHolder>() {
    val TAG = "BaseRecyclerAdapter"
    private var  mView:BaseCustomView<S> ?=null
    private var mList:MutableList<S> = mutableListOf()
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        Log.i(TAG, "onCreateViewHolder: $mView")
     return BaseViewHolder(mView)
    }

    override fun getItemCount(): Int {
       return mList.size
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        holder.bind(mList[position])
    }

    fun addLayout(view:BaseCustomView<S>) {
            this.mView = view
    }

    @SuppressLint("NotifyDataSetChanged")
    fun setData(list : MutableList<S>){
        this.mList = list
        notifyDataSetChanged()
    }

}